package yanyi.community.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yanyi.community.mapper.UserMapper;
import yanyi.community.model.User;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;
    public void createOrUpdate(User user){
        User model=userMapper.findByAccountId(user.getAccountId());
        if (model == null) {
            user.setGmtCreate(System.currentTimeMillis());
            user.setGmtModified(user.getGmtCreate());
            userMapper.insert(user);
        }else {
            model.setGmtModified(System.currentTimeMillis());
            model.setAvatarUrl(user.getAvatarUrl());
            model.setName(user.getName());
            model.setToken(user.getToken());
            userMapper.updateByPrimaryKeySelective(model);
        }
    }
}
